﻿// CMyEditWord.cpp: 实现文件
//

#include "pch.h"
#include "MY_PE_TOOL.h"
#include "CMyEditWord.h"


// CMyEditWord

IMPLEMENT_DYNAMIC(CMyEditWord, CEdit)

CMyEditWord::CMyEditWord()
{

}

CMyEditWord::~CMyEditWord()
{
}


BEGIN_MESSAGE_MAP(CMyEditWord, CEdit)
	ON_WM_CHAR()
END_MESSAGE_MAP()



// CMyEditWord 消息处理程序




void CMyEditWord::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
    //退格键
    if (nChar == 0x8)
    {
        CEdit::OnChar(nChar, nRepCnt, nFlags);
    }

    CString strText;
    GetWindowTextW(strText);

    DWORD dwNum = WideCharToMultiByte(CP_UTF8, 0, strText, -1, NULL, 0, NULL, NULL);

    WORD dwLow = LOWORD(GetSel());
    WORD dwHight = HIWORD(GetSel());

    //如果输入的字符大于4个并且没有选中字符（选中修改）
    if (dwNum > 4 && dwLow == dwHight)
    {
        return;
    }

    if (nChar <= '9' && nChar >= '0' || nChar <= 'F' && nChar >= 'A' || nChar <= 'f' && nChar >= 'a')
    {
        CEdit::OnChar(nChar, nRepCnt, nFlags);
    }

    return;
}
